/**********************************************************************
* <pre>
* FILE : ServiceActivityManage.java
* CLASS : ServiceActivityManage
*
* AUTHOR : PGM
*
* FUNCTION :服务活动管理.
*
*
*======================================================================
* CHANGE HISTORY LOG
*----------------------------------------------------------------------
* MOD. NO.| DATE     | NAME | REASON | CHANGE REQ.
*----------------------------------------------------------------------
*         |2010-05-17| PGM  | Created |
* DESCRIPTION:
* </pre>
***********************************************************************/
/**
 * $Id: ServiceActivityManage.java,v 1.16 2010/12/10 12:41:49 zuoxj Exp $
 */
package com.infodms.dms.actions.claim.serviceActivity;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import com.infodms.dms.bean.AclUserBean;
import com.infodms.dms.bean.TtAsActivityBean;
import com.infodms.dms.common.Constant;
import com.infodms.dms.common.ErrorCodeConstant;
import com.infodms.dms.common.getCompanyId.GetOemcompanyId;
import com.infodms.dms.dao.claim.serviceActivity.ServiceActivityManageDao;
import com.infodms.dms.dao.claim.serviceActivity.ServiceActivityManageItemDao;
import com.infodms.dms.exception.BizException;
import com.infodms.dms.po.TtAsActivityCharactorPO;
import com.infodms.dms.po.TtAsActivityMilagePO;
import com.infodms.dms.po.TtAsActivityNetitemPO;
import com.infodms.dms.po.TtAsActivityPO;
import com.infodms.dms.po.TtAsActivityPartsPO;
import com.infodms.dms.po.TtAsActivityRepairitemPO;
import com.infodms.dms.util.StringUtil;
import com.infodms.dms.util.sequenceUitl.SequenceManager;
import com.infoservice.mvc.context.ActionContext;
import com.infoservice.mvc.context.RequestWrapper;
import com.infoservice.po3.bean.PageResult;

/**
 * Function       :  服务活动管理
 * @author        :  PGM
 * CreateDate     :  2010-06-01
 * @version       :  0.1
 */
public class ServiceActivityManage {
	private Logger logger = Logger.getLogger(ServiceActivityManage.class);
	private ServiceActivityManageDao dao = ServiceActivityManageDao.getInstance();
	private ServiceActivityManageItemDao ItemDao = ServiceActivityManageItemDao.getInstance();
	private ActionContext act = ActionContext.getContext();//获取ActionContext
	private AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
	private final String ServiceActivityInitUrl = "/jsp/claim/serviceActivity/serviceActivityManageIndex.jsp";//查询页面
	private final String ServiceActivityAddUrl = "/jsp/claim/serviceActivity/serviceActivityManageAdd.jsp";//新增页面
	private final String ServiceActivityUpdateUrl = "/jsp/claim/serviceActivity/serviceActivityManageModify.jsp";//修改页面
	private final String ServiceActivityAddUpdateUrl = "/jsp/claim/serviceActivity/serviceActivityManageAddMaintion.jsp";//新增维护子表数据页面
	private final String ServiceActivityInfoUrl = "/jsp/claim/serviceActivity/serviceActivityDetail.jsp";//详细页面
	private final String ServiceActivityVehicleInfoUrl = "/jsp/claim/serviceActivity/vehicleInfo.jsp";//详细页面
	private final String milageURL = "/jsp/claim/serviceActivity/serviceActivityMilahe.jsp";//行驶里程限制页面
	
	
	
	/**
	 * Function       :  服务活动管理页面初始化
	 * @param         :  
	 * @return        :  serviceActivityManageInit
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	public void serviceActivityManageInit(){
		try {
			act.setForword(ServiceActivityInitUrl);
		} catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"服务活动管理");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**
	 * Function       :  根据条件查询服务活动管理中符合条件的信息，其中包括：尚未发布状态
	 * @param         :  request-活动编号、活动开始日期、活动结束日期
	 * @return        :  服务活动管理
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	public void serviceActivityManageQuery(){
		try {
			RequestWrapper request = act.getRequest();
			TtAsActivityBean ActivityBean = new TtAsActivityBean();
			String flag = request.getParamValue("flag");                    //修改返回标志
			String activityId = request.getParamValue("activityId");        //活动ID
			String checkedFlag = request.getParamValue("checkedFlag");      //第二次点击查询功能
			Long companyId=GetOemcompanyId.getOemCompanyId(logonUser);      //公司ID
			if(null!=flag&&!"".equals(flag)&&!"null".equals(flag)){
				ActivityBean.setActivityId(activityId);//活动ID
			}else{
				String activityCode = request.getParamValue("activityCode");    //活动编号
				String activityName = request.getParamValue("activity_name");   //活动名称
				String startdate = request.getParamValue("startDate");          //活动开始日期
				String enddate = request.getParamValue("endDate");             //活动结束日期
				ActivityBean.setActivityCode(activityCode);
				ActivityBean.setActivityName(activityName);
				ActivityBean.setStartdate(startdate);
				ActivityBean.setEnddate(enddate);
			}
			ActivityBean.setCompanyId(String.valueOf(companyId));
			Integer curPage = request.getParamValue("curPage") !=null ? Integer.parseInt(request.getParamValue("curPage")) : 1;
			PageResult<Map<String, Object>> ps = dao.getAllServiceActivityManageInfo(ActivityBean,curPage,Constant.PAGE_SIZE );
			act.setOutData("ps", ps);
			request.setAttribute("flag", flag);
			request.setAttribute("activityId", activityId);
			act.setForword(ServiceActivityInitUrl);
		}catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"服务活动管理");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/*
	 * 服务活动主页面第一次查询2
	 * 无经销商关联
	 */
	public void serviceActivityManageQuery2(){
		try {
			act.getResponse().setContentType("application/json");
			RequestWrapper request = act.getRequest();
			String activityCode = request.getParamValue("activityCode");    //活动编号
			String activityName = request.getParamValue("activity_name");   //活动名称
			String startdate = request.getParamValue("startDate");          //活动开始日期
			String enddate = request.getParamValue("endDate");             //活动结束日期
			String type = request.getParamValue("activityType");         //活动类型
			
			StringBuffer con = new StringBuffer();
			if(StringUtil.notNull(activityCode))
				con.append("and activity_code like '%").append(activityCode).append("%'\n");
			if(StringUtil.notNull(activityName))
				con.append("and activity_name like '%").append(activityName).append("%'\n");
			if(StringUtil.notNull(type))
				con.append("and activity_type = ").append(type).append("\n");
			if(StringUtil.notNull(startdate))
				con.append("and startdate>=to_date('").append(startdate).append(" 00:00:00','yyyy-MM-dd hh24:mi:ss')\n");
			if(StringUtil.notNull(enddate))
				con.append("and enddate<=to_date('").append(enddate).append(" 23:59:59','yyyy-MM-dd hh24:mi:ss')\n");
			int curPage = request.getParamValue("curPage") !=null ? Integer.parseInt(request.getParamValue("curPage")) : 1;
			int pageSize = 15 ;
			PageResult<Map<String,Object>> ps = dao.getServiceActivityInfo(con.toString(), pageSize, curPage) ;
			act.setOutData("ps", ps);
		}catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"服务活动管理");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**
	 * Function       :  增加服务活动管理信息初始化页面---服务活动范围TC_CODE查询
	 * @param         :  request
	 * @return        :  服务活动管理
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	public void serviceActivityManageArea(){
		RequestWrapper request = act.getRequest();
		try {
			TtAsActivityBean beforeVehicle=dao.serviceActivityVehicleBeforeVehicleArea();//售前车
		    TtAsActivityBean afterVehicle=dao.serviceActivityVehicleAfterVehicleArea();//售后车
		    request.setAttribute("beforeVehicle", beforeVehicle);//查询服务活动车辆范围---售前车
		    request.setAttribute("afterVehicle", afterVehicle);//查询服务活动车辆范围---售后车
		}catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"服务活动管理");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**
	 * Function       :  增加服务活动管理信息初始化页面
	 * @param         :  request
	 * @return        :  服务活动管理
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	public void serviceActivityManageAddInit(){
		RequestWrapper request = act.getRequest();
		try {
			this.serviceActivityManageArea();//服务活动范围TC_CODE查询方法
		    act.setForword(ServiceActivityAddUrl);
		}catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"服务活动管理");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**
	 * Function       :  增加服务活动管理信息
	 * @param         :  request---活动ID、活动编号、活动名称、活动类别、活动开始日期、活动结束日期
	 *                             处理方式、距活动结束日期几天上传活动总结、配件费用、工时费用
	 *                             索赔、索赔是否为固定费用、解决方案说明、索赔申请填写指导、服务活动活动状态
	 * @return        :  服务活动管理
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	@SuppressWarnings("static-access")
	public void serviceActivityManageAdd(){
		try {
			RequestWrapper request = act.getRequest();
			String activityId =SequenceManager.getSequence("");             //活动ID
			String activityCode = SequenceManager.getSequence("SAN");//request.getParamValue("activityCode");    //活动编号
			String activityName = request.getParamValue("activityName");    //活动名称
			String activityType = request.getParamValue("activityType");    //活动类型
			String activityKind = request.getParamValue("activityKind");    //活动类别
			String startdate = request.getParamValue("startDate");          //活动开始日期
			String enddate = request.getParamValue("endDate");              //活动结束日期
			String dealwith = request.getParamValue("dealwith");            //处理方式
			String uploadPrePeriod = request.getParamValue("uploadPrePeriod");//距活动结束日期几天上传活动总结
			String beforeVehicle = request.getParamValue("beforeVehicle"); //售前车
			String afterVehicle = request.getParamValue("afterVehicle");   //售后车
			String defaultA = request.getParamValue("default");            //结算指向
			String setDirect = "0" ;      //如果是按生产基地结算,则插入0.否则按生产基地
			if(defaultA.equals("2"))
				setDirect = request.getParamValue("yieldly");
			String singleCarNum = request.getParamValue("single_num");   //单台次活动次数
			String maxCar = request.getParamValue("car_max");             //单经销商活动总活动次数
			String activityFee = request.getParamValue("activityFee");     //活动费用
			String milage = request.getParamValue("misage");//是否里程限制
			//String partFee = request.getParamValue("partFee");              //配件费用
			//String worktimeFee = request.getParamValue("worktimeFee");      //工时费用
			String isClaim = request.getParamValue("isClaim");              //索赔
			String isFixfee = request.getParamValue("isFixfee");            //索赔是否为固定费用
			String solution = request.getParamValue("solution");            //解决方案说明
			String claimGuide = request.getParamValue("claimGuide");        //索赔申请填写指导
			Integer status=Constant.SERVICEACTIVITY_STATUS_01;              //服务活动管理--服务活动活动状态:[10681001:尚未发布;10681002:已经发布;10681003:重新发布]
			TtAsActivityPO ActivityPO=new TtAsActivityPO();
			ActivityPO.setActivityId(Long.parseLong(activityId));
			if (activityCode!=null&&!"".equals(activityCode)) {
			ActivityPO.setActivityCode(activityCode);
			}
			ActivityPO.setActivityName(activityName);
			if (activityType!=null&&!"".equals(activityType)) {
				ActivityPO.setActivityType(Integer.parseInt(activityType));
			}
			if(activityFee!=null&&!"".equals(activityFee)){
				ActivityPO.setActivityFee(Float.parseFloat(activityFee));
			}
			if (isFixfee!=null&&!"".equals(isFixfee)) {
				ActivityPO.setIsFixfee(Integer.parseInt(isFixfee));
			}
			if (activityKind!=null&&!"".equals(activityKind)) {
				ActivityPO.setActivityKind(Integer.parseInt(activityKind));
				if(Constant.SERVICEACTIVITY_KIND_02.toString().equals(activityKind))
					ActivityPO.setIsFixfee(1);
			}
			if(null!=startdate){
				DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
				ActivityPO.setStartdate(df.parse(startdate));
			}
			if(null!=enddate){
				DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
				ActivityPO.setEnddate(df.parse(enddate));
			}
			if (dealwith!=null&&!"".equals(dealwith)) {
				ActivityPO.setDealwith(Integer.parseInt(dealwith));
			}
			if (uploadPrePeriod!=null&&!"".equals(uploadPrePeriod)) {
				ActivityPO.setUploadPrePeriod(Integer.parseInt(uploadPrePeriod));
			}
			String VehicleArea =beforeVehicle+","+afterVehicle;//服务活动车辆范围：售前车\售后车
			if(!"".equals(beforeVehicle)&&null!=beforeVehicle&&null!=afterVehicle&&!"".equals(afterVehicle)){
				ActivityPO.setVehicleArea(VehicleArea);
			}
			if((!"".equals(beforeVehicle)||null!=beforeVehicle)&&(null==afterVehicle||"".equals(afterVehicle))){
				ActivityPO.setVehicleArea(beforeVehicle);
			}
			if(("".equals(beforeVehicle)||null==beforeVehicle)&&(null!=afterVehicle||!"".equals(afterVehicle))){
				ActivityPO.setVehicleArea(afterVehicle);
			}
			//免费保养只能是售后车
			if(Constant.SERVICEACTIVITY_KIND_02.toString().equals(activityKind)){
				ActivityPO.setVehicleArea(Constant.SERVICEACTIVITY_VEHICLE_AREA_02.toString());
			}
			/*if (partFee!=null&&!"".equals(partFee)) {
				ActivityPO.setPartFee(Float.parseFloat(partFee));
			}
			if (worktimeFee!=null&&!"".equals(worktimeFee)) {
				ActivityPO.setWorktimeFee(Float.parseFloat(worktimeFee));
			}*/
			if (isClaim!=null&&!"".equals(isClaim)) {
				ActivityPO.setIsClaim(Integer.parseInt(isClaim));
			}
			if(null != milage&&!"".equals(milage)) {
			  ActivityPO.setMilageConfine(Long.valueOf(milage));
			}
			ActivityPO.setSolution(solution);
			ActivityPO.setClaimGuide(claimGuide);
			ActivityPO.setStatus(status);
			ActivityPO.setCompanyId(logonUser.getCompanyId());//公司ID
			ActivityPO.setCreateBy(logonUser.getUserId());
			ActivityPO.setCreateDate(new Date());
			ActivityPO.setUpdateBy(logonUser.getUserId());
			ActivityPO.setUpdateDate(new Date());
			ActivityPO.setIsDel(Integer.parseInt(Constant.IS_DEL_00));//IS_DEL_01 = "1":逻辑删除;IS_DEL_00 = "0":逻辑未删除
			Long companyId=GetOemcompanyId.getOemCompanyId(logonUser);     //公司ID
			ActivityPO.setCompanyId(companyId);
			if(StringUtil.notNull(maxCar))
				ActivityPO.setMaxCar(Integer.parseInt(maxCar));
			if(StringUtil.notNull(singleCarNum))
				ActivityPO.setSingleCarNum(Integer.parseInt(singleCarNum));
			if(StringUtil.notNull(setDirect))
				ActivityPO.setSetDirect(Integer.parseInt(setDirect));
			dao.serviceActivityManageAdd(ActivityPO);
			this.serviceActivityManageAddAfter(activityId); //跳转到修改页面，维护车辆信息
		}catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"服务活动管理信息增加");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**
	 * Function       :  新增之后---查询服务管理活动信息
	 * @param         :  request-活动ID
	 * @return        :  服务管理活动信息
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	public void serviceActivityManageAddAfter(String activityId){ 
		RequestWrapper request = act.getRequest();
		try {
			TtAsActivityBean ActivityBean = new TtAsActivityBean();
			ActivityBean=dao.serviceActivityManageCommon(activityId);
			request.setAttribute("ActivityPO", ActivityBean);
			this.serviceActivityManageArea();//服务活动范围TC_CODE查询方法
			TtAsActivityBean VehicleArea  = dao.serviceActivityVehicleArea(activityId);//服务活动范围方法,用于回显
			String vicle=VehicleArea.getVehicleArea();
			String vicle1="";
			String vicle2="";
			if( null != vicle){
			if(-1 == vicle.indexOf(",")){ //YH 2010.11.29
				vicle1=vicle;
				vicle2=vicle;
			}else{
			String vv[]=vicle.split(",");
			vicle1=vv[0];
			vicle2=vv[1];
			}
		}
			request.setAttribute("vicle1", vicle1);
			request.setAttribute("vicle2", vicle2);
			request.setAttribute("activityId",activityId);
			act.setForword(ServiceActivityAddUpdateUrl);
		} catch(Exception e){
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"服务活动管理信息");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**
	 * Function       :  修改前置---查询服务管理活动信息
	 * @param         :  request-活动ID
	 * @return        :  服务管理活动信息
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	public void serviceActivityManageUpdateInit(){ 
		RequestWrapper request = act.getRequest();
		try {
			String activityId   = request.getParamValue("activityId");      //活动ID
			TtAsActivityBean ActivityBean=new TtAsActivityBean();
			ActivityBean=dao.serviceActivityManageCommon(activityId);
			request.setAttribute("ActivityPO", ActivityBean);
			this.serviceActivityManageArea();//服务活动范围TC_CODE查询方法
			TtAsActivityBean VehicleArea  = dao.serviceActivityVehicleArea(activityId);//服务活动范围方法,用于回显
			String vicle=VehicleArea.getVehicleArea();
			String vicle1="";
			String vicle2="";
			if(!"".equals(vicle)&&null!=vicle){
				if(vicle.indexOf(",")==-1){
					vicle1=vicle;
					vicle2=vicle;
				}else{
				String vv[]=vicle.split(",");
				vicle1=vv[0];
				vicle2=vv[1];
				}
			}
			request.setAttribute("vicle1", vicle1);
			request.setAttribute("vicle2", vicle2);
			request.setAttribute("activityId", activityId);
			act.setForword(ServiceActivityUpdateUrl);
		} catch(Exception e){
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"服务活动管理信息");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**
	 * Function       :  修改服务活动管理信息
	 * @param         :  request---活动ID、活动编号、活动名称、活动类型、活动类别、活动开始日期、活动结束日期
	 *                             处理方式、距活动结束日期几天上传活动总结、配件费用、工时费用、索赔、索赔是否为固定费用
	 *                             解决方案说明、索赔申请填写指导、服务活动活动状态、修改内容
	 * @return        :  服务活动管理
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	@SuppressWarnings("static-access")
	public void serviceActivityManageUpdate(){
		try {
			RequestWrapper request = act.getRequest();
			String	flag = request.getParamValue("flag");                   //修改状态标识
			String activityId   = request.getParamValue("activityId");      //活动ID
			//String activityCode = request.getParamValue("activityCode");    //活动编号
			String activityName = request.getParamValue("activityName");    //活动名称
			String activityType = request.getParamValue("activityType");    //活动类型
			String activityKind = request.getParamValue("activityKind");    //活动类别
			String startdate = request.getParamValue("startDate");          //活动开始日期
			String enddate = request.getParamValue("endDate");              //活动结束日期
			String dealwith = request.getParamValue("dealwith");            //处理方式
			String uploadPrePeriod = request.getParamValue("uploadPrePeriod");//距活动结束日期几天上传活动总结
			String beforeVehicle = request.getParamValue("beforeVehicle"); //售前车
			String afterVehicle = request.getParamValue("afterVehicle");   //售后车
			String single_num = request.getParamValue("single_num");       //单台服务次数
			String max_car = request.getParamValue("car_max");             //单经销商活动次数
			String defaultA = request.getParamValue("default");            //结算指向
			String setDirect = "0" ;      //如果是按生产基地结算,则插入0.否则按生产基地
			String  misage  = request.getParamValue("misage");//里程限制
			if(defaultA.equals("2"))
				setDirect = request.getParamValue("yieldly");
			
			String activityFee = request.getParamValue("activityFee");     //活动费用
			
			//String partFee = request.getParamValue("partFee");              //配件费用
			//String worktimeFee = request.getParamValue("worktimeFee");      //工时费用
			String isClaim = request.getParamValue("isClaim");              //索赔
			String isFixfee = request.getParamValue("isFixfee");            //索赔是否为固定费用
			
			String solution = request.getParamValue("solution");            //解决方案说明
			String claimGuide = request.getParamValue("claimGuide");        //索赔申请填写指导
			Integer status=null;											//活动状态
			//if("add".equals(flag)){//添加时维护主数据和子数据，活动状态为：尚未发布;
				 status=Constant.SERVICEACTIVITY_STATUS_01;              //服务活动管理--服务活动活动状态:[10681001:尚未发布;10681002:已经发布;10681003:重新发布]
			//}else{//修改时维护主数据和子数据，活动状态为：重新发布;
			//	 status=Constant.SERVICEACTIVITY_STATUS_03;              //服务活动管理--服务活动活动状态:[10681001:尚未发布;10681002:已经发布;10681003:重新发布]
			//}
			TtAsActivityPO ActivityPOCon=new TtAsActivityPO();
			ActivityPOCon.setActivityId(Long.parseLong(activityId));        //以活动ID为条件进行修改
			TtAsActivityPO ActivityPO=new TtAsActivityPO();                 //修改内容
			ActivityPO.setMilageConfine(Long.valueOf(misage));
			//ActivityPO.setActivityCode(activityCode);
			ActivityPO.setActivityName(activityName);
			if (isFixfee!=null&&!"".equals(isFixfee)) {
				TtAsActivityRepairitemPO RepairitemPO=new TtAsActivityRepairitemPO();
				RepairitemPO.setActivityId(Long.parseLong(activityId));
				ItemDao.deleteItemWorkHoursOption(RepairitemPO);//根据活动ID删除活动工时
				TtAsActivityPartsPO PartsPO=new TtAsActivityPartsPO();
				PartsPO.setActivityId(Long.parseLong(activityId));
				ItemDao.deleteItemPartsOption(PartsPO);//根据活动ID删除活动配件
				TtAsActivityNetitemPO NetitemPO=new TtAsActivityNetitemPO();
				NetitemPO.setActivityId(Long.parseLong(activityId));
				ItemDao.deleteItemOthersOption(NetitemPO);//根据活动ID删除活动其他活动项目
				ActivityPO.setIsFixfee(Integer.parseInt(isFixfee));
			}else{
				ActivityPO.setIsFixfee(0);
			}
			if (activityType!=null&&!"".equals(activityType)) {
				ActivityPO.setActivityType(Integer.parseInt(activityType));
			}
			if (activityKind!=null&&!"".equals(activityKind)) {
				ActivityPO.setActivityKind(Integer.parseInt(activityKind));
				if(Constant.SERVICEACTIVITY_KIND_02.toString().equals(activityKind))
					ActivityPO.setIsFixfee(1);
			}
			if(null!=startdate){
				DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
				ActivityPO.setStartdate(df.parse(startdate));
			}
			if(null!=enddate){
				DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
				ActivityPO.setEnddate(df.parse(enddate));
			}
			if (dealwith!=null&&!"".equals(dealwith)) {
			ActivityPO.setDealwith(Integer.parseInt(dealwith));
			}
			if (uploadPrePeriod!=null&&!"".equals(uploadPrePeriod)) {
			ActivityPO.setUploadPrePeriod(Integer.parseInt(uploadPrePeriod));
			}
			String VehicleArea =beforeVehicle+","+afterVehicle;//服务活动车辆范围：售前车、售后车
			if(!"".equals(beforeVehicle)&&null!=beforeVehicle&&null!=afterVehicle&&!"".equals(afterVehicle)){
				ActivityPO.setVehicleArea(VehicleArea);
			}
			if((!"".equals(beforeVehicle)||null!=beforeVehicle)&&(null==afterVehicle||"".equals(afterVehicle))){
				ActivityPO.setVehicleArea(beforeVehicle);
			}
			if(("".equals(beforeVehicle)||null==beforeVehicle)&&(null!=afterVehicle||!"".equals(afterVehicle))){
				ActivityPO.setVehicleArea(afterVehicle);
			}
			if(!"".equals(activityFee)&&null!=activityFee){
				ActivityPO.setActivityFee(Float.parseFloat(activityFee));
			}
			if(StringUtil.notNull(max_car))
				ActivityPO.setMaxCar(Integer.parseInt(max_car));
			if(StringUtil.notNull(single_num))
				ActivityPO.setSingleCarNum(Integer.parseInt(single_num));
			ActivityPO.setSetDirect(Integer.parseInt(setDirect));
			/*if (partFee!=null&&!"".equals(partFee)) {
			ActivityPO.setPartFee(Float.parseFloat(partFee));
			}
			if (worktimeFee!=null&&!"".equals(worktimeFee)) {
			ActivityPO.setWorktimeFee(Float.parseFloat(worktimeFee));
			}*/
			if (isClaim!=null&&!"".equals(isClaim)) {
				ActivityPO.setIsClaim(Integer.parseInt(isClaim));
			}else{
				TtAsActivityRepairitemPO RepairitemPO=new TtAsActivityRepairitemPO();
				RepairitemPO.setActivityId(Long.parseLong(activityId));
				ItemDao.deleteItemWorkHoursOption(RepairitemPO);//根据活动ID删除活动工时
				TtAsActivityPartsPO PartsPO=new TtAsActivityPartsPO();
				PartsPO.setActivityId(Long.parseLong(activityId));
				ItemDao.deleteItemPartsOption(PartsPO);//根据活动ID删除活动配件
				TtAsActivityNetitemPO NetitemPO=new TtAsActivityNetitemPO();
				NetitemPO.setActivityId(Long.parseLong(activityId));
				ItemDao.deleteItemOthersOption(NetitemPO);//根据活动ID删除活动其他活动项目
				ActivityPO.setIsClaim(1);
			}
			ActivityPO.setSolution(solution);
			ActivityPO.setClaimGuide(claimGuide);
			ActivityPO.setStatus(status);
			ActivityPO.setUpdateBy(logonUser.getUserId());
			ActivityPO.setUpdateDate(new Date());
			dao.serviceActivityManageUpdate(ActivityPOCon,ActivityPO);
			TtAsActivityCharactorPO CharactorPO=new TtAsActivityCharactorPO();
			if("11321001".equals(beforeVehicle)){//服务活动车辆范围：售前车
				CharactorPO.setActivityId(Long.parseLong(activityId));
				dao.serviceActivityManageCharactorDelete(CharactorPO);//当选择售前车时，不允许维护车辆性质
			}
			act.setForword(ServiceActivityInitUrl);//返回查询主界面
		}catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"服务活动管理信息增加");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**
	 * Function       :  删除服务活动管理信息
	 * @param         :  request-活动ID
	 * @return        :  服务活动管理信息
	 * @throws        :  ParseException
	 * LastUpdate     :  2010-06-01
	 */
	@SuppressWarnings("static-access")
	public void serviceActivityManageDelete(){ 
		RequestWrapper request = act.getRequest();
		String activityId=request.getParamValue("activityId");//活动ID
		TtAsActivityPO  ActivityPoContent =new TtAsActivityPO();
		try{
			ActivityPoContent.setUpdateBy(logonUser.getUserId());//修改人
			ActivityPoContent.setUpdateDate(new Date());//修改时间
			ActivityPoContent.setIsDel(Integer.parseInt(Constant.IS_DEL_01));//IS_DEL_01 = "1" 逻辑删除;IS_DEL_00 = "0" 逻辑未删除
			dao.serviceActivityManageDelete(activityId,ActivityPoContent);
			act.setOutData("returnValue", 1);//returnValue 值：1，表示成功
			//act.setForword(ServiceActivityInitUrl);
		  }catch(Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.DELETE_FAILURE_CODE,"删除服务活动信息");
			logger.error(logonUser,e1);
		 	act.setException(e1);
		  }
	}
	/**
	 * Function       :  查询服务活动信息-明细
	 * @param         :  request-活动ID、活动工时、活动配件、活动其它项目、车型列表、车龄定义列表、车辆性质
	 * @return        :  服务活动信息
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	public void getActivityIdInfo(){ 
		RequestWrapper request = act.getRequest();
		String activityId=request.getParamValue("activityId");//活动ID
		try {
			TtAsActivityBean ActivityBean=dao.getServiceActivityByActivityIdInfo(activityId);//查询服务活动信息-明细
			List<TtAsActivityBean> ActivityBeanList=dao.getWorkingHoursInfoList(activityId);//活动工时
			List<TtAsActivityBean> ActivityPartsList=dao.getPartsList(activityId);//活动配件
			List<TtAsActivityBean> ActivityNetItemList=dao.getNetItemList(activityId);//活动其它项目
			List<TtAsActivityBean> ActivityVhclMaterialGroupList=dao.getVhclMaterialGroupList(activityId);//车型列表
			List<TtAsActivityBean> ActivitygetActivityAgeList=dao.getActivityAgeList(activityId);//车龄定义列表
			List<TtAsActivityBean> ActivityCharactorList=dao.getActivityCharactorList(activityId);//车辆性质//getMilageActivity
			 List<Map<String, Object>> ActivityMileageList=dao.getMilageActivity(Long.valueOf(activityId));//里程限制
			if(ActivityCharactorList!=null){
			Iterator<TtAsActivityBean> it=ActivityCharactorList.iterator();
			while(it.hasNext()){
				TtAsActivityBean ActivityBeans =it.next();
				if(String.valueOf(Constant.SERVICEACTIVITY_CHARACTOR_01).equals(ActivityBeans.getCarCharactor())){//出租车
					ActivityBeans.setCodeDesc("出租车");
				}else if(String.valueOf(Constant.SERVICEACTIVITY_CHARACTOR_02).equals(ActivityBeans.getCarCharactor())){//私家车
					ActivityBeans.setCodeDesc("私家车");
				}else{//公务车
					ActivityBeans.setCodeDesc("公务车");
				}
			}
			}
			request.setAttribute("ActivityBean", ActivityBean);
			request.setAttribute("ActivityBeanList", ActivityBeanList);
			request.setAttribute("ActivityPartsList", ActivityPartsList);
			request.setAttribute("ActivityNetItemList", ActivityNetItemList);
			request.setAttribute("ActivityVhclMaterialGroupList", ActivityVhclMaterialGroupList);
			request.setAttribute("ActivitygetActivityAgeList", ActivitygetActivityAgeList);
			request.setAttribute("ActivityCharactorList", ActivityCharactorList);
			act.setOutData("ActivityMileageList", ActivityMileageList);
			this.serviceActivityManageArea();//服务活动范围TC_CODE查询方法
			TtAsActivityBean VehicleArea  = dao.serviceActivityVehicleArea(activityId);//服务活动范围方法,用于回显
			String vicle=VehicleArea.getVehicleArea();
			String vicle1="";
			String vicle2="";
			if(vicle.indexOf(",")==-1){
				vicle1=vicle;
				vicle2=vicle;
			}else{
			String vv[]=vicle.split(",");
			vicle1=vv[0];
			vicle2=vv[1];
			}
			request.setAttribute("vicle1", vicle1);
			request.setAttribute("vicle2", vicle2);		
			
			act.setForword(ServiceActivityInfoUrl);
		} catch(Exception e){
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"服务活动信息详细信息");
			logger.error(logonUser,e1);
			act.setException(e1);
		 }
		}
		/**
		 * Function       :  查询服务活动信息-车辆信息
		 * @param         :  request-活动ID
		 * @return        :  服务活动信息
		 * @throws        :  Exception
		 * LastUpdate     :  2010-06-01
		 */
	
		public void getActivityVehicleListInfo(){ 
			RequestWrapper request = act.getRequest();
			String activityId=request.getParamValue("activityId");//活动ID
			try {
				Integer curPage = request.getParamValue("curPage") !=null ? Integer.parseInt(request.getParamValue("curPage")) : 1;
				PageResult<Map<String, Object>> ps = dao.getActivityVehicleList(activityId,request.getParamValue("vin"),curPage,Constant.PAGE_SIZE );
				act.setOutData("ps", ps);
				request.setAttribute("activityId", activityId);
				act.setForword(ServiceActivityVehicleInfoUrl);
			} catch(Exception e){
				BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"服务活动信息详细信息--车辆信息");
				logger.error(logonUser,e1);
				act.setException(e1);
			}
	}
		/**
		 * Function       :  查询服务活动信息-车辆信息初始化页面
		 * @param         :  request-活动ID
		 * @return        :  服务活动信息
		 * @throws        :  Exception
		 * LastUpdate     :  2010-06-01
		 */
		public void getActivityVehicleListInfoInit(){ 
			RequestWrapper request = act.getRequest();
			String activityId=request.getParamValue("activityId");//活动ID
			request.setAttribute("activityId", activityId);
			act.setForword(ServiceActivityVehicleInfoUrl);
		}
		
		
		
		public void getActivityMilage(){
			RequestWrapper request = act.getRequest();
			String activeId  = request.getParamValue("activeId");//获取服务活动ID
			Integer curPage = request.getParamValue("curPage") !=null ? Integer.parseInt(request.getParamValue("curPage")) : 1;
			try {
				PageResult<Map<String, Object>> ps = dao.getMilage(50, curPage,activeId);
				List<Map<String,Object>> list = dao.getMilageActivity(Long.valueOf(activeId));
				act.setOutData("ps", ps);
				act.setOutData("list", list);
				act.setOutData("activeId", activeId);
				act.setForword(milageURL);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		public void insertActivityMilage() throws NumberFormatException, Exception{
			try{
			RequestWrapper request = act.getRequest();
			String  activeId = request.getParamValue("activeId");
			String[] IDS = request.getParamValues("baoyangId");//隐藏ID
			String[] checkIds = request.getParamValues("checkId");//选中ID
			dao.deleteMilage(activeId);
			if(checkIds!=null){
				for(int i=0;i<checkIds.length;i++){
					String id = checkIds[i];
					List<Map<String,Object>> list = dao.getMilageId(Long.valueOf(id));
					TtAsActivityMilagePO PO = new TtAsActivityMilagePO();
					if(list.get(0).get("START_MILEAGE")!=null){
					PO.setMilageStart(Double.valueOf(list.get(0).get("START_MILEAGE").toString()));
					}
					if(list.get(0).get("END_MILEAGE")!=null){
					PO.setMilageEnd(Double.valueOf(list.get(0).get("END_MILEAGE").toString()));
					}
					PO.setActivityId(Long.valueOf(activeId));
					PO.setCreateDate(new Date());
					PO.setCreateBy(logonUser.getUserId());
					PO.setFreeTimes(Integer.valueOf(list.get(0).get("FREE_TIMES").toString()));
					PO.setId(Long.valueOf(SequenceManager.getSequence("")));
					dao.insertMilage(PO);
				}
			}
			}
			catch(Exception e){
				BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"服务活动信息详细信息--车辆信息");
				logger.error(logonUser,e1);
				act.setException(e1);
			}
			
		
			
			
		}
		
		
		
}